package org.jeecg.modules.wlhy.hybank.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.wlhy.hybank.entity.HyBank;
import org.jeecg.modules.wlhy.hybank.service.IHyBankService;
import org.jeecg.modules.wlhy.utils.BankTypeUtil;
import org.jeecg.modules.wlhy.utils.InitService;
import org.jeecg.modules.wlhy.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description: hy_bank
 * @Author: jeecg-boot
 * @Date:   2021-11-26
 * @Version: V1.0
 */
@Api(tags="hy_bank")
@RestController
@RequestMapping("/hybank/hyBank")
@Slf4j
public class HyBankController extends JeecgController<HyBank, IHyBankService> {
	@Autowired
	private IHyBankService hyBankService;

	@Autowired
	private   UserUtil userUtil;

	@Autowired private InitService initService;

	@ApiOperation(value="hy_bank-分页列表查询", notes="hy_bank-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(HyBank hyBank,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		if(!userUtil.isSys()){
			return Result.error("没有权限查看");
		}
		QueryWrapper<HyBank> queryWrapper = QueryGenerator.initQueryWrapper(hyBank, req.getParameterMap());
		Page<HyBank> page = new Page<HyBank>(pageNo, pageSize);
		IPage<HyBank> pageList = hyBankService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	

	@AutoLog(value = "hy_bank-添加")
	@ApiOperation(value="hy_bank-添加", notes="hy_bank-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody HyBank hyBank) {
		if(!userUtil.isSys()){
			return Result.error("没有权限操作");
		}
		hyBankService.save(hyBank);

		List<HyBank> bankList = hyBankService.list();
		BankTypeUtil.initBankType(bankList);

		initService.setPayCenterBankList(bankList);

		return Result.OK("添加成功！");
	}
	

	@AutoLog(value = "hy_bank-编辑")
	@ApiOperation(value="hy_bank-编辑", notes="hy_bank-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody HyBank hyBank) {
		if(!userUtil.isSys()){
			return Result.error("没有权限操作");
		}
		hyBankService.updateById(hyBank);

		List<HyBank> bankList = hyBankService.list();
		BankTypeUtil.initBankType(bankList);
		initService.setPayCenterBankList(bankList);
		return Result.OK("编辑成功!");
	}
	
//	/**
//	 *   通过id删除
//	 *
//	 * @param id
//	 * @return
//	 */
//	@AutoLog(value = "hy_bank-通过id删除")
//	@ApiOperation(value="hy_bank-通过id删除", notes="hy_bank-通过id删除")
//	@DeleteMapping(value = "/delete")
//	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
//		hyBankService.removeById(id);
//		return Result.OK("删除成功!");
//	}
	

//	/**
//	 * 通过id查询
//	 *
//	 * @param id
//	 * @return
//	 */
//	@ApiOperation(value="hy_bank-通过id查询", notes="hy_bank-通过id查询")
//	@GetMapping(value = "/queryById")
//	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
//		HyBank hyBank = hyBankService.getById(id);
//		if(hyBank==null) {
//			return Result.error("未找到对应数据");
//		}
//		return Result.OK(hyBank);
//	}
//
//    /**
//    * 导出excel
//    *
//    * @param request
//    * @param hyBank
//    */
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletRequest request, HyBank hyBank) {
//        return super.exportXls(request, hyBank, HyBank.class, "hy_bank");
//    }
//
//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, HyBank.class);
//    }

}
